function Watcher(vm,exp,pathchFn) {
  this.depIds = {}
  this.$patchFn = pathchFn
  this.$vm = vm
  this.getter = this.parsePath(exp)
  this.value = this.get()
}

Watcher.prototype = {
  // 更新
  update () {
    this.run()
  },
  // 执行更新操作
  run () {
    var oldval = this.value
    var newval = this.get()
    if (oldval === newval) {
      return
    }
    this.$patchFn.call(this.$vm, newval)
  },
  // 订阅Dep
  addDep(dep) {
    if (this.depIds.hasOwnProperty(dep.id)) {
      return
    }
    dep.addSub(this)
    this.depIds[dep.id] = dep
  },
  // 获取exp对于的值，这是会激活observer的get事件
  get: function() {
    Dep.target = this
    var value  =this.getter.call(this.$vm, this.$vm._data)
    Dep.target = null
    return value
  },
  // 获取exp的对应值
  parsePath:function(path) {
    var segments = path.split('.');
    return function(obj) {
      for(let i = 0; i < segments.length; i++) {
        if (!obj) return
        obj = obj[segments[i]]
      }
      return obj
    }
  }
}